<%@ page language="java" contentType="text/html; charset=utf-8"%>
<html>
<head>
<%@ include file="/extjs/include/all.jsp"%>
<link href="${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl/userModule/page/css/authority.css" rel="stylesheet" type="text/css">
<title>其它资源列表</title>
</head>
<body>
<div id="result" style="width:100%"></div>
</body>
</html>
<script>

Ext.onReady(function(){

	var roleId = '<%=request.getParameter("roleId")%>';
	var sm = new Ext.grid.CheckboxSelectionModel();
	var resultWidth = Ext.get("result").getWidth();
	var cm = new Ext.grid.ColumnModel([ 
	    new Ext.grid.RowNumberer(), 
	    sm,
	    	{header:'资源',dataIndex:'id',width:resultWidth*0.3},    
	        {header:'名称',dataIndex:'name',width:resultWidth*0.3}, 
	        {header:'描述',dataIndex:'descn',width:resultWidth*0.3}
	    ]); 
	cm.defaultSortable = true; 
	
 	var ds = new Ext.data.Store({ 
        proxy: new Ext.data.HttpProxy({
        	url:'${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl::/roleModule/roleAction/QueryOtherResourceList.action?roleId='+roleId
        }), 
        reader: new Ext.data.JsonReader({ 
                root: 'withoutRes' 
	    }, 
	    [
	    	{name: 'id',mapping:'id'}, 
	        {name: 'name',mapping:'name'}, 
	        {name: 'descn',mapping:'descn'} 
	    ]), 
	    remoteSort:true 
    }); 
		       
	var grid = new Ext.grid.GridPanel({ 
	    el: 'result', 
	    title:'资源列表', 
	    height:600, 
	    bodyStyle:'width:100%',
	    stripeRows: true,
	    collapsible:true,
	    trackMouseOver:false, 
	    loadMask: {msg:'正在加载数据，请稍侯……'}, 
	    store:ds, 
	    cm: cm, 
	    sm:sm, 
	    tbar: [{
            text:'添加资源到角色',
            tooltip:'添加资源到角色',
            iconCls:'add',
            handler: add
        },'-',{
            text:'返回',
            tooltip:'返回',
            iconCls:'back',
            handler: function(){
            	//window.history.back();
            	window.location = 'roleResourceList.jsp';
            }
        }]/*,
        bbar: new Ext.PagingToolbar({ 
	            pageSize: 20, 
	            store: ds, 
	            displayInfo: true, 
	            displayMsg: '当前显示 {0} - {1}条记录 /共 {2}条记录', 
	            emptyMsg: "没有数据显示" 
	    }) */
	});     
					
    ds.load({params:{start:0, limit:20}}); 
    grid.render();   
    
    function add(){
          	arr_Records = sm.getSelections();
	    if (arr_Records.length == 0) {
	        Ext.MessageBox.alert('警告', '最少需要选择一条记录!');
	    } else {
			Ext.MessageBox.confirm('确认', '确认添加所选资源到角色?', addResource);
		}
	}
			
			
	function addResource(btn){
        if(btn == 'yes'){
	        arr_Records = sm.getSelections();
	        var addStr = ''; 		 
	   	   	for (var i = 0, len = arr_Records.length; i < len; i++){    
	   	   	  	 addStr += arr_Records[i].data.id;  
	   	   	  	 addStr += ',' ;	
			} 
		    if(addStr.length > 0){
 					addStr = addStr.substring(0,addStr.length - 1) ;
			}
		    Ext.Ajax.request({
			     method : 'POST',                             //发送方式.'POST'或'GET',一般是'POST'
			     url: '${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl::/roleModule/roleAction/InsertResourceByRole.action',                  //发送到页面
			     success:function(request){                   //发送成功的回调函数
			       var myResult = Ext.util.JSON.decode(request.responseText);
			       Ext.Msg.alert('信息','恭喜你，添加成功！', function(){
			       		window.history.back();
			       }); 
			     },
			     failure:function(){                          //发送失败的回调函数
			       Ext.Msg.alert("错误", "发送失败，请重试！");
			     },
			     params:{
			     		resourceList:addStr,
           	     		role_id:roleId
			     } 
	     	});
        	ds.load({params:{start:0, limit:20}}); 
        } 
    }	            
});
</script>